package com.along.game.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.along.framework.dao.base.IBaseDao;

import com.along.game.dao.GameConfigDAO;

import com.along.game.model.Music;
import com.along.game.model.SysInfo;
@Repository("gameConfigDAO")
public class GameConfigDaoImpl implements GameConfigDAO{

	//音乐配置
	
	@Resource(name="baseDao")
private IBaseDao<Music,Long> musicdao;
	@Resource(name="baseDao")
	private IBaseDao<SysInfo,Long> sysinfodao;
	
	  /**
	 * 添加音乐信息
	 * @param htGameTableVO
	 * @return
	 */
		public int loadMusic(Music musicVO){
		
		
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder();
		sb.append("insert into music (");
		sb.append(" id, music_name, music_url, music_type");
		sb.append(") values(seq_music_id.nextVal,?,?,?)");
	return	musicdao.jdbc().update(sb.toString(),new Object[]{
	    musicVO.getMusicName(),
		musicVO.getMusicUrl(),
		musicVO.getMusicType()
		});
		
	
	
	
	}

	    
	     /**
	      * 根据ID查询音乐的详细
	      * @param send_id
	      * @return
	      * @throws BizException
	      */
	     public Music queryMusicDetail(String  music_id){
	    	 
	    	 

	    		// TODO Auto-generated method stub
		 		StringBuilder sb = new StringBuilder();
		 		sb.append(" select id, music_name, music_url, music_type  from music where id=?");
		return	(Music)musicdao.jdbc().queryForObject(sb.toString(),new Object[]{music_id},Music.class);
	    	 
	     }
	     
		 /**
	 	  * 保存音乐信息 
	 	  * @param htMusicVO
	 	  * @return
	 	  * @throws BizException
	 	  */
	 	public int saveMusic(Music  musicVO){
	 		
	 		
	 		
	 		// TODO Auto-generated method stub
	 		StringBuilder sb = new StringBuilder();
	 		sb.append(" update  music set   music_name=?, music_url=?, music_type=?  where id=?");
			return	musicdao.jdbc().update(sb.toString(),new Object[]{
				musicVO.getMusicName(),
				musicVO.getMusicUrl(),
				musicVO.getMusicType(),
				musicVO.getId()
				});
	 		
	 		
	 	}
	 	/**
	 	 * 
	 	 * @param pic_id 要删除的音乐
	 	 * @return
	 	 * @throws BizException
	 	 */
	 	public int removeMusic(String music_id){
	 		
	 		
			// TODO Auto-generated method stub
	 		StringBuilder sb = new StringBuilder();
	 		sb.append(" delete music   where id=?");
			return	musicdao.jdbc().update(sb.toString(),
				new Object[]{ music_id});
	 		
	 	}
	 		


	 	/**
	 	 * 依据条件查询音乐列表
	 	 * @param pageSize  页码大小
	 	 * @param curPage   当前页
	 	 * @param musicVO  musicVO
	 	 * @return
	 	 * @throws BizException
	 	 */
		public List queryMusic(int startrow, int endrow, Music musicVO){
			
			
		
	 		StringBuilder sb = new StringBuilder();
	 		sb.append(" select id, music_name, music_url, music_type from( select ta.*,rownum rn ");
	 		sb.append(" from (select ma.*,rownum  tn from(select *  from music  t )ma)  ");
	 		sb.append(" ta where tn<=? ) f where f.rn>? ");
			return	musicdao.jdbc().list(sb.toString(),new Object[]{endrow,startrow}, Music.class);
			
		}
	   
		/**
	     * 根据条件查询音乐总记录数
	     * @param  tourOrderVO
	     * @return
	     * @throws BizException
	     */
	    public int queryMusicCount(Music musicVO){
	    	
	      	StringBuilder sb = new StringBuilder();
	    	String queryFiledstr="";
		    sb.append("select count(*)   from music ");
		
			Object[] queryField=queryFiledstr.split(","); 
   
         if(queryFiledstr.equals(""))
 			return	musicdao.jdbc().getJdbcTemplate().queryForInt(sb.toString());
 		else
 			return	musicdao.jdbc().getJdbcTemplate().queryForInt(sb.toString(),queryField);
	    	
	    }

         

	    /**
	     * 读取音乐列表中指定的条数
	     * @param readnum
	     * @return
	     */
	    public List  queryMusic(int readnum){
	    	
	    	
	    	 
	    	StringBuilder sb = new StringBuilder();
	    	sb.append("select ta.*,rownum rn ");
	    			sb.append("from (select ma.*,rownum  tn from(select *  from music  t )ma) ");
	    		sb.append("	ta where tn<=? ");
				return	musicdao.jdbc().list(sb.toString(),new Object[]{readnum}, Music.class);
	    	
	    }
	    
	    
	
	    
	
	
	//系统配置
	
	    /**
		 * 添加系统配置信息
		 * @param htGameTableVO
		 * @return
		 */
			public int loadSysInfo(SysInfo sysInfoVO){


				// TODO Auto-generated method stub
				StringBuilder sb = new StringBuilder();
				sb.append("insert into gametable (");
				sb.append(" id,attribute_name, attribute_value, attribute_detail");
				sb.append(") values(seq_sys_info_id.nextVal,?,?,?)");
			return  sysinfodao.jdbc().update(sb.toString(),new Object[]{
				sysInfoVO.getAttributeName(),
				sysInfoVO.getAttributeValue(),
				sysInfoVO.getAttributeDetail()
				});
				
			
			}

		    
		     /**
		      * 根据ID查询系统配置的详细
		      * @param send_id
		      * @return
		      * @throws BizException
		      */
		     public SysInfo querySysInfoDetail(String sysinfo_id){
		    	 
		    		// TODO Auto-generated method stub
			 		StringBuilder sb = new StringBuilder();
			 		sb.append(" select id, attribute_name, attribute_value, attribute_detail where  id=?");
			return	(SysInfo)sysinfodao.jdbc().queryForObject(sb.toString(),new Object[]{sysinfo_id},SysInfo.class);
		     
		     
		     }
		     
			 /**
		 	  * 保存系统配置信息 
		 	  * @param htSysInfoVO
		 	  * @return
		 	  * @throws BizException
		 	  */
		 	public int saveSysInfo(SysInfo  sysInfoVO){
		 		
		 		// TODO Auto-generated method stub
		 		StringBuilder sb = new StringBuilder();
		 		sb.append(" update  gametable set   attribute_name=?, attribute_value=?, attribute_detail=?  where id=?");
				return	sysinfodao.jdbc().update(sb.toString(),new Object[]{
					sysInfoVO.getAttributeName(),
					sysInfoVO.getAttributeValue(),
					sysInfoVO.getAttributeDetail()
					});
		 		
		 		
		 	}
		 	/**
		 	 * 
		 	 * @param pic_id 要删除的系统配置
		 	 * @return
		 	 * @throws BizException
		 	 */
		 	public int removeSysInfo(String sys_id){
		 		
		 		// TODO Auto-generated method stub
		 		StringBuilder sb = new StringBuilder();
		 		sb.append(" delete from sys_info   where id=?");
				return	sysinfodao.jdbc().update(sb.toString(),
					new Object[]{ sys_id});
				
		 		
		 		
		 	}
		 		


		 	/**
		 	 * 依据条件查询系统配置列表
		 	 * @param pageSize  页码大小
		 	 * @param curPage   当前页
		 	 * @param sysInfoVO  sysInfoVO
		 	 * @return
		 	 * @throws BizException
		 	 */
			public List querySysInfo(int startrow, int endrow, SysInfo sysInfoVO){
				
			
				// TODO Auto-generated method stub
		 		StringBuilder sb = new StringBuilder();
		 		sb.append(" select id, attribute_name, attribute_value, attribute_detail from( select ta.*,rownum rn ");
		 		sb.append(" from (select ma.*,rownum  tn from(select *  from sys_info  t )ma)  ");
		 		sb.append(" ta where tn<=? ) f where f.rn>? ");
				return	sysinfodao.jdbc().list(sb.toString(),new Object[]{endrow,startrow}, SysInfo.class);
					
			
			}
		   
			/**
		     * 根据条件查询系统配置总记录数
		     * @param  tourOrderVO
		     * @return
		     * @throws BizException
		     */
		    public int querySysInfoCount(SysInfo sysInfoVO){
		    
		    	
		    	StringBuilder sb = new StringBuilder();
		    	String queryFiledstr="";
			    sb.append("select count(*)   from sys_info ");
			
				Object[] queryField=queryFiledstr.split(","); 
	   
	         if(queryFiledstr.equals(""))
	 			return	sysinfodao.jdbc().getJdbcTemplate().queryForInt(sb.toString());
	 		else
	 			return	sysinfodao.jdbc().getJdbcTemplate().queryForInt(sb.toString(),queryField);
		    	
		    }

	         

		    /**
		     * 读取系统配置列表中指定的条数
		     * @param readnum
		     * @return
		     */
		    public List  querySysInfo(int readnum){
		    	
		    	
		    	 
		    	StringBuilder sb = new StringBuilder();
		    	sb.append("select ta.*,rownum rn ");
		    			sb.append("from (select ma.*,rownum  tn from(select *  from sys_info t )ma) ");
		    		sb.append("	ta where tn<=? ");
					return	sysinfodao.jdbc().list(sb.toString(),new Object[]{readnum},SysInfo.class);
		    	
		    }
		    
		    
		
		    
	    
	    
	    
	
}
